package com.efast.dmom.mes.datahandlers.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.SupplierPart;
import com.efast.dmom.mes.dao.entity.SupplierPartDao;
import com.efast.dmom.mes.datahandlers.base.ConfigurationDataHandler;
import com.efast.dmom.mes.entity.SupplierPartEntity;
import com.efast.dmom.mes.util.TimeUtil;

/**
 * 
 * @author WJ
 * @date 2020/2/20
 *
 */
@Component
public class SupplierPartDataHandler extends ConfigurationDataHandler<SupplierPart>{

	@Autowired
	private SupplierPartDao supplierPartDao;
	
	@Override
	public ResultBean save(SupplierPart obj) {
		ResultBean resultBean = new ResultBean();
		if (obj.getInnerData() != null) {
			obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
			obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//			obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			obj.getInnerData().setRowStatus(1);
			obj.getInnerData().setRowTrxId(1);
			supplierPartDao.save(obj.getInnerData());
		}
		return resultBean;
	}
	
	@Override
	public ResultBean delete(SupplierPart obj) {
		ResultBean resultBean = new ResultBean();
		if(obj.getInnerData() != null){
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		//	obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			supplierPartDao.delete(obj.getInnerData());
		}
		return resultBean;
	}
	
	@Override
	public ResultBean update(SupplierPart obj) {
		ResultBean resultBean = new ResultBean();
		if (obj.getInnerData() != null) {
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		//	obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			supplierPartDao.update(obj.getInnerData());
		}
		return resultBean;
	}

	public SupplierPart getByName(String name) {
		SupplierPart supplierPart = new SupplierPart();
		supplierPart.setInnerData(supplierPartDao.getByName(name));
		return supplierPart;
	}

	public SupplierPart getCustomerPartBySupplierIdAndPartId(long supplierId, long partId) {
		SupplierPart supplierPart = new SupplierPart();
		supplierPart.setInnerData(supplierPartDao.getCustomerPartBySupplierIdAndPartId(supplierId,partId));
		return supplierPart;
	}

	public SupplierPart getById(long id) {
		SupplierPart supplierPart = new SupplierPart();
		supplierPart.setInnerData(supplierPartDao.getById(id));
		return supplierPart;
	}

	public List<SupplierPart> getSupplierPartBySupplierId(long supplierId) {
		List<SupplierPart> supplierPartList = new ArrayList<SupplierPart>();
		List<SupplierPartEntity> entityList = supplierPartDao.getSupplierPartBySupplierId(supplierId);
		if (entityList != null && entityList.size() > 0) {
			for(SupplierPartEntity entityData : entityList) {
				SupplierPart supplierPart = new SupplierPart();
				supplierPart.setInnerData(entityData);
				supplierPartList.add(supplierPart);
			}
			return supplierPartList;
		}
		return null;
	}

	public List<SupplierPart> getSupplierPartByPartId(long partId) {
		List<SupplierPart> supplierPartList = new ArrayList<SupplierPart>();
		List<SupplierPartEntity> entityList = supplierPartDao.getSupplierPartByPartId(partId);
		if (entityList != null && entityList.size() > 0) {
			for(SupplierPartEntity entityData : entityList) {
				SupplierPart supplierPart = new SupplierPart();
				supplierPart.setInnerData(entityData);
				supplierPartList.add(supplierPart);
			}
			return supplierPartList;
		}
		return null;
	}

	public int getSupplierPartCountBySupplierId(long id) {
		return supplierPartDao.getSupplierPartCountBySupplierId(id);
	}

	@Override
	public ResultBean saveBatch(List<SupplierPart> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean updateBatch(List<SupplierPart> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean deleteBatch(List<SupplierPart> obj) {
		// TODO Auto-generated method stub
		return null;
	}

}
